# -*- coding: UTF-8 -*-
import urllib
import urllib2
import socket
import sys

reload(sys)
sys.setdefaultencoding('utf-8')
socket.setdefaulttimeout(30)
f = open("E:/toOrigin/myNote/pythonSpider/proxy/data.txt")
lines = f.readlines()
proxys = []
for i in range(0,len(lines)):
    ip = lines[i].strip("\n").split("\t")
    proxy_host = "http://"+ip[0]+":"+ip[1]
    proxy_temp = {"http":proxy_host}
    print proxy_host
    proxys.append(proxy_temp)
url = "https://book.douban.com/subject/2567698/collections?start=80"
for proxy in proxys:
    try:
        #res = urllib.urlopen(url,proxies=proxy).read().decode('utf-8')
        print str(proxy)
        #print res
    except Exception,e:
        print proxy
        print e
        continue
print "test"
proxy_host = "https://211.159.171.58:80"
proxy_temp = {"https":proxy_host}
print proxy_host
proxy_handler=urllib2.ProxyHandler({'https':'https://211.159.171.58:80'})
opener=urllib2.build_opener(proxy_handler)
urllib2.install_opener(opener)
res = urllib2.urlopen(url).read().decode('utf-8')
#print str(proxy)
print res
